﻿using System;
using System.Collections.Generic;
using studentSubsidy.Dao;
using studentSubsidy.Entity.User;
using studentSubsidy.Models;
using studentSubsidy.Utils;

namespace studentSubsidy.Service
{
    public class UserService
    {
        private UserDao _userDao = new UserDao();

        public void userRegister(RegisterQuery registerQuery)
        {
            //密码加密存储
            registerQuery.Role = "student";
            _userDao.insertUser(registerQuery);
        }

        public User userLogin(UserLoginQuery userLoginQuery)
        {
            string password = AESUtils.Encrypt(userLoginQuery.Password);
            userLoginQuery.Password = password;
            List<User> user = _userDao.ifUserByPassword(userLoginQuery);
            if (user.Count==0)
            {
                return null;
            }
            else
            {
                return user[0];
            }
        }
    }
}